<!DOCTYPE html>
<html>
    <head>
        <title>河南全一安防</title>
        <Link Rel="SHORTCUT ICON" href="/amdin/images/head_logo.png">
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <link rel="stylesheet" type="text/css" href="/admin/css/zhuce.css"/>
        <script src="/admin/js/jquery-1.11.1.min.js"></script>
        <script src="/admin/js/rem.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
    <!-- 连接服务器时释放 -->
    <!-- {{csrf_field()}} -->
        <div class="header">
            <img src="/admin/images/logo1.png"/>
            <p>已有账号？去<a href="/admin/login/index">登录</a></p>
        </div>
        <div class="body">
        <!--    <p>注册帐号</p> -->
            <div class="first information">
                <label for="" class="title">账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
                <input type="text" value="" name="account" id="account" class="input" placeholder="请输入代理商账号"/>
                <div class="tishi" id="a_error">
               
                </div>
            </div>
            <div class="information">
                <label for="" class="title">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</label>
                <input type="password" name="password" id="password" value="" class="input" placeholder="6-16位密码，区分大小写"/>
                <div class="tishi" id="p_error">
                    
                </div>
            </div>
            <div class="information">
                <label for="" class="title">确认密码：</label>
                <input type="password" name="password1" id="password1" value="" class="input" placeholder="再次输入密码"/>
                <div class="tishi" id="p_error1">
                    
                </div>
            </div>
            <div class="information">
                <label for="" class="title">联&nbsp;&nbsp;系&nbsp;人：</label>
                <input type="text" name="linkman" id="linkman" value="" class="input" placeholder="请输入联系人"/>
                <div class="tishi" id="l_error">
                    
                </div>
            </div>
            <div class="information">
                <label for="" class="title">手机号码：</label>
                <input type="tel" name="phone" id="phone" value="" class="input" placeholder="请输入手机号码"/>
                <div class="tishi" id="t_error">
                    
                </div>
            </div>
            <div class="information">
                <label for="" class="title">公司名称：</label>
                <input type="text" name="agent_name" id="agent_name" value="" class="input" placeholder="请输入公司名称"/>
                <div class="tishi" id="an_error">
                    
                </div>
            </div>
            <div class="information">
                <label for="" class="title">上级代理：</label>
                <select class="input" name="agent_pid" id="agent_pid">
                    <option value="0">请选择代理商</option>
                    <!-- @foreach($allAgent as $v) -->
                        <option value="{{$v['id']}}">{{$v['agent_name']}}</option>
                <!--    @endforeach -->
                </select>
                <div class="tishi" id="ap_error">
                    
                </div>
            </div>
        
           <!--  <div class="information">
                <div class="tishi">
                </div>
            </div> -->
            <div class="information">
                <p><input type="submit" id="sub" value="注&nbsp;&nbsp;册"/></p>
            </div>
        </div>
        <div class="footer">
            <p>© 2017 郑州全一安防科技有限公司 版权所有</p>         
        </div>
    </body>
</html>
<script>
    //账号
    $('#account').blur(function () {
        var account = $('#account').val();
        var a_preg = /^[a-zA-Z_][a-zA-Z0-9_]{3,11}$/
        if(!a_preg.test(account)){
            $('#a_error').html('请以字母开头输入4~12位字母数字下划线')
        }else{
            $.ajax(
                {
                    type:'post',
                    url:'/admin/reg/test',
                    async:false,
                    data:{
                        "_token": $("input[name=_token]").val(),
                        'account':account,
                    },
                    dateType:'json',
                    success:function (str) {
                        var data = jQuery.parseJSON(str);
                        if(data.status == '-1'){
                            $('#a_error').html(data.msg)
                        }else{
                            $('#a_error').html('')
                        }
                    }
                }
            )
        }
    });
    //密码
    $('#password').blur(function(){
        var password = $('#password').val();
        var p_preg = /^[a-zA-Z0-9_]{6,18}$/
        if(!p_preg.test(password)){
            $('#p_error').html('请输入6~18位字母数字下划线')
        }else{
            $('#p_error').html('')
        }
    });

    //验证密码
    $('#password1').blur(function(){
        var password = $('#password').val();
        var password1 = $('#password1').val();
        if(password != password1 || password == ''){
            $('#p_error1').html('未输入密码或两次密码不一致')
        }else{
            $('#p_error1').html('')
        }
    });

    //联系人
    $('#linkman').blur(function(){
        var linkman = $('#linkman').val();
        if(linkman == ''){
            $('#l_error').html('联系人不能为空')
        }else{
            $('#l_error').html('')
        }
    });

    //公司名称
    $('#agent_name').blur(function(){
        var agent_name = $('#agent_name').val();
        if(agent_name == ''){
            $('#an_error').html('公司名称不能为空')
        }else{
            $('#an_error').html('')
        }
    });

    //手机号
    $('#phone').blur(function () {
        var phone = $('#phone').val();
        var t_preg = /^1(3|4|5|7|8)\d{9}$/
        if(!t_preg.test(phone)){
            $('#t_error').html('手机号格式不正确')
        }else{
            $('#t_error').html('')
        }
    })

    //提交处理
    $('#sub').click(function () {
        var account = $('#account').val();
        var password = $('#password').val();
        var password1 = $('#password1').val();
        var linkman = $('#linkman').val();
        var agent_name = $('#agent_name').val();
        var agent_pid = $('#agent_pid').val();
        var phone = $('#phone').val();
        var a_preg = /^[a-zA-Z0-9_][a-zA-Z0-9_]{3,11}$/
        var p_preg = /^[a-zA-Z0-9_]{6,18}$/
        var t_preg = /^1(3|4|5|7|8)\d{9}$/
        if(!a_preg.test(account)){
            $('#a_error').html('请以字母开头输入4~12位字母数字下划线')
        }else{

            if(!p_preg.test(password)){
                $('#p_error').html('请输入6~18位字母数字下划线')
            }else{
                $('#p_error').html('')
                if(password != password1 || password == ''){
                    $('#p_error1').html('未输入密码或两次密码不一致')
                }else{
                    $('#p_error1').html('')
                    if(linkman == ''){
                        $('#l_error').html('联系人不能为空')
                    }else{
                        $('#l_error').html('')
                        if(agent_name == ''){
                            $('#an_error').html('公司名称不能为空')
                        }else{
                            $('#an_error').html('')
                            if(!t_preg.test(phone)){
                                $('#t_error').html('手机号格式不正确')
                            }else{
                                $('#t_error').html('')
                                if(agent_pid == 0){
                                    $('#ap_error').html('请选择父级代理')
                                }else{
                                    $('#ap_error').html('')
                                    //var verify = $('#verify').val();
                                    //ajax请求
                                    $.ajax(
                                        {
                                            type:'post',
                                            url:'/admin/reg/approve',
                                            async:false,
                                            data:{
                                                "_token": $("input[name=_token]").val(),
                                                'account':account,
                                                'password':password,
                                                'linkman':linkman,
                                                'agent_name':agent_name,
                                                'agent_pid':agent_pid,
                                                'phone':phone
                                                //'verify':verify
                                            },
                                            dateType:'json',
                                            success:function (str) {
                                                var data = jQuery.parseJSON(str);
                                                alert(data.msg)
                                            }
                                        }
                                    )
                                }
                            }
                        }
                    }
                }
            }
        }
    })
</script>

